// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright @ Huawei Technologies Co., Ltd. 2020-2020. ALL rights reversed.
 */
#ifdef CONFIG_EULEROS_KBOX_ADD_PRINTK_NOTIFIER
#include <linux/os_kbox.h>
#include <linux/kernel.h>
#include <linux/smp.h>
#include <linux/sched.h>
#include <uapi/asm-generic/errno-base.h>

int g_kbox_record_cpu = -1;
int g_kbox_record_pid = -1;

KBOX_STORE_LOG_FUN kbox_store_printk;

void kbox_set_cpu_and_pid(void)
{
	g_kbox_record_cpu = smp_processor_id();
	g_kbox_record_pid = current->pid;
}
EXPORT_SYMBOL(kbox_set_cpu_and_pid);

void kbox_clear_cpu_and_pid(void)
{
	g_kbox_record_cpu = -1;
	g_kbox_record_pid = -1;
}
EXPORT_SYMBOL(kbox_clear_cpu_and_pid);

int kbox_register_store_interface(KBOX_STORE_LOG_FUN kbox_store_log_fn)
{
	if ((void *)kbox_store_log_fn == NULL || !kern_addr_valid((unsigned long)kbox_store_log_fn))
		return -EINVAL;

	kbox_store_printk = kbox_store_log_fn;
	return 0;
}
EXPORT_SYMBOL(kbox_register_store_interface);

/* note: kbox_store_printk function must not be called when unregister. */
void kbox_unregister_store_interface(void)
{
	kbox_store_printk = NULL;
}
EXPORT_SYMBOL(kbox_unregister_store_interface);
#endif
